
import time
from selenium.webdriver.support.ui import Select

'''商品添加的模块'''
class Item():
    '''商品添加的类'''

    def add(self,driver,listpa):
        '''添加商品'''
        driver.find_element_by_link_text('商品中心').click()
        time.sleep(1)
        driver.find_element_by_link_text('添加').click()
        # WebDriverWait(driver,5,0.5).until(lambda driver:driver.find_element_by_css_selector('dd[class=valid]'))
        #填写新增商品的信息
        Select(driver.find_element_by_id('category_id')).select_by_value('5')
        driver.find_element_by_name('name').send_keys(listpa[3])
        driver.find_element_by_name('goods_no').send_keys(listpa[5])
        elements = driver.find_elements_by_css_selector('input[type=checkbox]')
        elements[0].click()
        driver.find_element_by_css_selector('button[type=button]').click()
        time.sleep(1)
        driver.switch_to.frame('Openupimg_dialog')
        #选择本地图片
        driver.find_element_by_name('upfile').send_keys('C:\\Users\\Administrator\\Desktop\\TinyShop\\比基尼\\timg.jpg')
        driver.find_element_by_css_selector('button[class=button]').click()
        driver.switch_to_default_content()
        driver.find_element_by_name('store_nums').send_keys(listpa[8])
        driver.find_element_by_name('warning_line').send_keys(listpa[9])
        driver.find_element_by_name('weight').send_keys(listpa[10])
        driver.find_element_by_name('sell_price').send_keys(listpa[11])
        driver.find_element_by_name('market_price').send_keys(listpa[12])
        driver.find_element_by_name('cost_price').send_keys(listpa[13])
        driver.find_element_by_css_selector('button[id=open_spec]').click()
        driver.switch_to_frame('Openspec_list')
        time.sleep(2)
        driver.find_element_by_link_text('尺码[女式]').click()
        driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[1]/div[2]/ul[6]/li[9]/input').click()
        driver.find_element_by_css_selector('button[class=focus_button]').click()
        driver.switch_to_default_content()
        driver.find_element_by_css_selector('input[value=提交]').click()
        return listpa[3]
